package com.sunfeng.chap4.begintransfile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @description:
 * @author: 孙 峰
 * @time: 2020/11/9 16:21
 */
public class Client {
    public static void main(String[] args) {
        try {
            String pngFile = "c:\\a.png";
            FileInputStream pngFileInputStream = new FileInputStream(new File(pngFile));
            byte[] byteArray = new byte[2048];
            Socket socket = new Socket("127.0.0.1", 8088);
            OutputStream outputStream = socket.getOutputStream();
            //读一下 进入循环
            int readLength = pngFileInputStream.read(byteArray);
            // 经典
            while (readLength != -1) {
                // 写  读
                outputStream.write(byteArray, 0, readLength);
                readLength = pngFileInputStream.read(byteArray);
            }
            outputStream.close();
            pngFileInputStream.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
